import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store'
import Config from '@/public/config'
Vue.use(Router)

let routerConfig = [
  {
    path: '/',
    name: 'Redirect',
    redirect:'/home'
  }
];

import Home from './home.js'
routerConfig = routerConfig.concat(Home)

var routerInstance = new Router({
  routes: routerConfig
});

routerInstance.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  } else {
    document.title = Config.sysName;
  }
  if (to.meta.requireAuth && !store.state.hasLogin) {
    location.href = Config.loginPage + '&backurl=' + encodeURIComponent(location.href);
    return;
  }

  next();
})

export default routerInstance;